//index.js
//获取应用实例
var post = {};
var app = getApp()
Page({
    data: {
    },

    submit: function () {
        if (!post.name) {
            app.wxToast.warn('请输入收货人姓名');
            return;
        }


        if (!post.phone) {
            app.wxToast.warn('请输入收货人联系电话');
            return;
        }

        if (!post.phone.match(/^1[0-9]{10}$/g)) {
            app.wxToast.warn('请输入11位手机号');
            return;
        }
        if (!this.data.province || !this.data.city || !this.data.county) {
            app.wxToast.warn('请选择区域');
            return;
        }
        if (!post.address) {
            app.wxToast.warn('请输入详细地址');
            return;
        }
        post.province = this.data.province;
        post.city = this.data.city;
        post.county = this.data.county;
        if (this.data.loading) {
            return;
        }
        this.setData({ loading: true });
        wx.showLoading({
            title: "保存中..."
        })
        app.http.post("address/add", {
            data: post,
        }).then(res => {
            this.setData({ loading: false });
            wx.navigateBack({
                delta: 1
            });
            wx.hideLoading()
        })
    },

    onInput: function (evt) {
        var key = evt.currentTarget.dataset.key;
        var val = evt.detail.value;
        post[key] = val;
    },

    onShow: function () {
        wx.setNavigationBarTitle({
            title: this.data.id ? "编辑收货地址" : "添加收货地址",
        });
    },
    bindChange: function (e) {
        var val = e.detail.value
        this.setData({
            province: val[0],
            city: val[1],
            county: val[2],
        })

    },

    onLoad: function (options) {


    }
})
